﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace SimpleTerminal
{
    public partial class PreferenceForm : Form
    {
        public PreferenceForm()
        {
            InitializeComponent();
            // Preference.Default.
            colorsComboBox_Background.SelectedColor = Preference.Default.Terminal_BackColor;
            colorsComboBox_Forecolor.SelectedColor = Preference.Default.Terminal_ForeColor;
            cursorColorBox.SelectedColor = Preference.Default.Terminal_CursorColor;
            cursorTextColorBox.SelectedColor = Preference.Default.Terminal_CursorTextColor;
            //字体初始化
            fontComboBox1.SelectedFont = Preference.Default.Terminal_Font.Name;

            textComboBox1.SelectedText = ""+Preference.Default.Terminal_Font.Size;

            textBoxSplit.Text = Preference.Default.Terminal_SplitChar;

            //初始化预览窗体
            labelPreview.Font = Preference.Default.Terminal_Font;
            labelPreview.BackColor = Preference.Default.Terminal_BackColor;
            labelPreview.ForeColor = Preference.Default.Terminal_ForeColor;

            //滚动区
            scollBackSize.Value = Preference.Default.Terminal_ScrollBackSize;

            //右键菜单
            switch (Preference.Default.MouseRightClick)
            {
                case 0:
                    SelectMouseRightClick.Text = "打开上下文菜单";
                    break;
                case 1:
                    SelectMouseRightClick.Text = "复制选择的文本";
                    break;
                default:
                    SelectMouseRightClick.Text = "不进行任何操作";
                    break;
            }

        }



    

        private void BtnOk_Click(object sender, EventArgs e)
        {
            //保存字体与背景设置
            Preference.Default.Terminal_BackColor = colorsComboBox_Background.SelectedColor;
            Preference.Default.Terminal_ForeColor = colorsComboBox_Forecolor.SelectedColor;
            Preference.Default.Terminal_CursorColor = cursorColorBox.SelectedColor;
            Preference.Default.Terminal_CursorTextColor = cursorTextColorBox.SelectedColor;
            Preference.Default.Terminal_Font = new Font(fontComboBox1.SelectedFont, Convert.ToInt32(textComboBox1.SelectedText));
            Preference.Default.Terminal_SplitChar = textBoxSplit.Text;
            Preference.Default.Terminal_ScrollBackSize = (int)scollBackSize.Value;
            string text = SelectMouseRightClick.Text;
            if ("打开上下文菜单".Equals(text))
            {
                Preference.Default.MouseRightClick = 0;
            }
            else if ("复制选择的文本".Equals(text))
            {
                Preference.Default.MouseRightClick = 1;
            }
            else
            {
                Preference.Default.MouseRightClick = 2;
            }
            Preference.Default.Save();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();

        }

        private void ColorsComboBox_Forecolor_SelectColorChanged(object sender, EventArgs e)
        {
            labelPreview.ForeColor = colorsComboBox_Forecolor.SelectedColor;
        }

        private void ColorsComboBox_Background_SelectColorChanged(object sender, EventArgs e)
        {
            labelPreview.BackColor = colorsComboBox_Background.SelectedColor;
        }



        private void CursorColorBox_SelectColorChanged(object sender, EventArgs e)
        {

        }  
        
        private void FontComboBox_SelectFontSizeChanged(object sender, EventArgs e)
        {
            labelPreview.Font = new Font(fontComboBox1.SelectedFont,
              Convert.ToInt32(textComboBox1.SelectedText));
        }
        private void FontComboBox_SelectFontNameChanged(object sender, EventArgs e)
        {
            labelPreview.Font = new Font(fontComboBox1.SelectedFont,
                Convert.ToInt32(textComboBox1.SelectedText));
        }

        private void label10_Click(object sender, EventArgs e)
        {

        }
    }
}
